<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Fx_Header
 *
 * @author anhdt
 */
class Fx_Header extends Fx_Block {

    protected $_title = '';

    protected $_metaData = array('description' => '', 'keywords' => array());
    
    public function __construct() {
        parent::__construct();
    }

    public function __call($method, $args) {
        $method_type = substr($method, 0, 3);
        $param = substr($method, 2);
        switch ($method_type) {
            case 'set':
                if (isset($args[0])) {
                    $this->_params[$param] = $args[0];
                }
                return $this;
            break;
            case 'get':
                if (isset($this->_params[$param])) {
                    return $this->_params[$param];
                }
                return NULL;
            break;
        }
    }

    /**
     * Set Title Of Page
     * @param Fx_Header (Header Of Page)
     * @return Fx_Page
     */
    public function setTitle($title = '') {
        if (!is_string($title)) {
            return $this;
        }
        $this->_title = $title;
        return $this;
    }

    /**
     * Get Title Of Page
     * @return String
     */
    public function getTitle() {
        return $this->_title;
    }

    /**
     * Set Description Of Page
     * @param String
     * @return Fx_Page
     */
    public function setDescription($desc = '') {
        if (is_string($desc) && !empty($desc)) {
            $this->_metaData['description'] = $desc;
        }
        return $this;
    }

    /**
     * Get Description Of Page
     * @return String
     */
    public function getDescription() {
        return (string)$this->_metaData['description'];
    }

     /**
     * Set MetaData Of Page
     * @param Array
     * @return Fx_Page
     */
    public function setMetaData($metaData = array()) {
        if (!is_array($metaData) || count($metaData) == 0) {
            return $this;
        }
        $this->_metaData = $metaData;
        return $this;
    }

     /**
     * Clear Meta Data Of Page
     * @return Fx_Page
     */
    public function clearMetaData() {
        $this->_metaData = array();
        return $this;
    }

    /**
     * Get MetaData Of Page
     * @return Array (Meta Data Of Page)
     */
    public function getMetaData() {
        return (array)$this->_metaData;
    }

    /**
     * Add Keywords To Metadata
     * @return Fx_Header
     */
    public function setKeywords($keywords = array()) {
        if (is_array($keywords)) {
           $this->_metaData['keywords'] = $keywords;
        }
        return $this;
    }
    
    /**
     * Add Keywords To Metadata
     * @return Fx_Header
     */
    public function addKeyword($keyword = '') {
        if (is_string($keyword)) {
            $this->_metaData['keywords'][$keyword] = $keyword;
        } else if (is_array($keyword)) {
            foreach ($keyword as $key) {
                $this->addKeyword($key);
            }
        }
        return $this;
    }

    /**
     * Get Keywords From Metadata
     * @return Array (Meta Data Of Page)
     */
    public function getKeywords($keyword = '') {
        return (array)$this->_metaData['keywords'];
    }

    /**
     * Clean Keywords
     * @return Fx_Header
     */
    public function cleanKeywords() {
        $this->_metaData['keywords'] = array();
        return $this;
    }
}
?>
